package com.foreveross.fetl.application.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foreveross.fetl.application.IOfficChannelSpreadApplication;
import com.foreveross.fetl.common.application.BaseApplicationImpl;
import com.foreveross.fetl.core.domain.freight.OfficChannelSpreadEntity;
import com.foreveross.fetl.vo.OfficChannelSpreadVO;

@Transactional
@Service("officChannelSpreadApplication")
public class OfficChannelSpreadApplicationImpl extends BaseApplicationImpl
		implements IOfficChannelSpreadApplication {
	
	

	@Override
	public void removeList(List<OfficChannelSpreadVO> listVo) {
		List<OfficChannelSpreadEntity> listEntity=new ArrayList<OfficChannelSpreadEntity>();
		for(OfficChannelSpreadVO vo:listVo){
			OfficChannelSpreadEntity entity =this.voToEntity(vo);
			listEntity.add(entity);
		}
	
		OfficChannelSpreadEntity officChannelSpreadEntity=new OfficChannelSpreadEntity();
		officChannelSpreadEntity.removeList(listEntity);
		
	}

	@Override
	public void saveList(List<OfficChannelSpreadVO> listVo) {
		List<OfficChannelSpreadEntity> listEntity=new ArrayList<OfficChannelSpreadEntity>();
		for(OfficChannelSpreadVO vo:listVo){
			OfficChannelSpreadEntity entity =this.voToEntity(vo);
			listEntity.add(entity);
		}
		OfficChannelSpreadEntity officChannelSpreadEntity=new OfficChannelSpreadEntity();
		officChannelSpreadEntity.saveList(listEntity);

	}
	


	@Override
	public List<OfficChannelSpreadVO> findByCondition(Date reportDate,
			Date flightDate, String fromCity, String toCity, String flightNo,
			String channel, String hbaseKey) {
		List<OfficChannelSpreadVO> listVo =new ArrayList<OfficChannelSpreadVO>();
		OfficChannelSpreadEntity entity =new OfficChannelSpreadEntity();
		List<OfficChannelSpreadEntity> listEntity = entity.findByCondition(
				reportDate, flightDate, fromCity, toCity, flightNo, channel,
				hbaseKey);
		if(null!=listEntity && !listEntity.isEmpty()){
			for(OfficChannelSpreadEntity en :listEntity){
				OfficChannelSpreadVO vo=this.EntityToVO(en);
				listVo.add(vo);
			}
		}
		return listVo;
	}
	
	private OfficChannelSpreadEntity voToEntity(OfficChannelSpreadVO vo){
		OfficChannelSpreadEntity entity =new OfficChannelSpreadEntity();
		entity.setId(vo.getId());
		entity.setChannelName(vo.getChannelName());
		entity.setHbaseName(vo.getHbaseName());
		entity.setChannel(vo.getChannel());
		entity.setChannelPrice(vo.getChannelPrice());
		entity.setFlightDate(vo.getFlightDate());
		entity.setFlightNo(vo.getFlightNo());
		entity.setFromCity(vo.getFromCity());
		entity.setFromCityName(vo.getFromCityName());
		entity.setGrabTime(vo.getGrabTime());
		entity.setHbaseKey(vo.getHbaseKey());
		entity.setHomePrice(vo.getHomePrice());
		entity.setReportDate(vo.getReportDate());
		entity.setToCity(vo.getToCity());
		entity.setToCityName(vo.getToCityName());
		return entity;
	}
	
	private OfficChannelSpreadVO EntityToVO(OfficChannelSpreadEntity entity){
		OfficChannelSpreadVO vo =new OfficChannelSpreadVO();
		vo.setId(entity.getId());
		vo.setChannelName(entity.getChannelName());
		vo.setHbaseName(entity.getHbaseName());
		vo.setChannel(entity.getChannel());
		vo.setChannelPrice(entity.getChannelPrice());
		vo.setFlightDate(entity.getFlightDate());
		vo.setFlightNo(entity.getFlightNo());
		vo.setFromCity(entity.getFromCity());
		vo.setFromCityName(entity.getFromCityName());
		vo.setGrabTime(entity.getGrabTime());
		vo.setHbaseKey(entity.getHbaseKey());
		vo.setHomePrice(entity.getHomePrice());
		vo.setReportDate(entity.getReportDate());
		vo.setToCity(entity.getToCity());
		vo.setToCityName(entity.getToCityName());
		return vo;
	}
}
